package com.GreenIce.android.util;

import java.lang.reflect.Field;

import com.GreenIce.android.R;

/**
 * get resource id by name;
 * @author Jas0n
 *
 */
public class ResourceIdentifier {
	/**
	 * 返回R.raw中名字为name的静态属性
	 * @param name
	 * @return
	 */
	public static int getRawID(String name){
		int result = 0;
		try {
			Field f = R.raw.class.getDeclaredField(name);
			result = f.getInt(null);
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (NoSuchFieldException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}		
		return result;
	}
	/**
	 * 返回R.drawable中名字为name的静态属性
	 * @param name
	 * @return
	 */
	public static int getDrawableID(String name){
		int result = 0;
		try {
			Field f = R.drawable.class.getDeclaredField(name);
			result = f.getInt(null);
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (NoSuchFieldException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}		
		return result;
	}
}
